<?php

namespace App\Models\Article;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ArticleCategoryMappingsModel extends BaseModel
{
    use HasFactory, KfUid, KfSoftDeletes;

    protected $fillable = [
        "articleId",
        "categoryId",
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
        'isDeleted',
        "sort"
    ];

    const SORT_TYPE_0    = 0;
    const SORT_TYPE_1    = 1;
    const SORT_TYPE_2    = 2;
    const SORT_TYPE_TEXT = [
        self::SORT_TYPE_0 => "默认排序",
        self::SORT_TYPE_1 => "最早发布",
        self::SORT_TYPE_2 => "最新发布",
    ];

    protected $table = "article_category_mappings";


    /**
     * @return HasOne
     */
    public function articleRel(): HasOne
    {
        return $this->hasOne(ArticleModel::class, "id", "articleId");
    }

    /**
     * @return HasMany
     */
    public function articleUserRelationRel(): HasMany
    {
        return $this->HasMany(ArticleUserRelationModel::class, "articleId", "articleId");
    }

    /**
     * @return HasOne
     */
    public function articleCategoryRel(): HasOne
    {
        return $this->hasOne(ArticleCategoryModel::class, "id", "categoryId");
    }
}
